package com.gao.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gao.pojo.Class;
import com.gao.pojo.User;
import com.gao.service.ClassService;
import com.gao.service.UserService;
import com.gao.service.impl.ClassServiceImpl;
import com.gao.vo.Class_users;
import com.gao.vo.UserClas;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author GaoHuoHuo
 * @since 2020-03-14
 */
@Controller
//@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userServiceImpl;
    @Autowired
    private ClassService classServiceImpl;

    private Logger logger = LoggerFactory.getLogger ( UserController.class );

    @RequestMapping("user_login")
    public String ceshi(User user, HttpServletRequest request) {
        QueryWrapper<User> wrapper = new QueryWrapper<> ( user );
        User user1 = userServiceImpl.getOne ( wrapper );
        if (user1 == null) {
            return "redirect:/index.jsp";
        } else {
            HttpSession session = request.getSession ();
            session.setAttribute ( "user", user1 );
            /*查询学生并返回去 以班级的形式返回*/
            List<Class_users> clas = classServiceImpl.selClassList ();
            session.setAttribute ( "class_users", clas );
            return "xx";
        }
    }

    @RequestMapping("userPage")
    @ResponseBody
    public PageInfo<UserClas> page(@RequestParam(defaultValue = "1") Integer index) {

        PageInfo<UserClas> pageInfo = userServiceImpl.selUserClasPage ( index, 3 );
      //  pageInfo.getList ()
        return pageInfo;
    }

}
